package com.wen.moudle.Managers;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.wen.config.EquipmentFilter.EquipmentLevelFilter;
import com.wen.entry.Result;
import com.wen.entry.bean.Equipment;
import com.wen.entry.bean.EquipmentCombineEquipment;
import com.wen.moudle.Account;
import com.wen.moudle.abstractManager;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class EquipmentManager extends abstractManager {
    public final static Integer HAT = 1;
    public final static Integer SHOE = 2;
    public final static Integer CLOTHES = 3;
    public final static Integer FIST = 4;

    public EquipmentManager(Account account) {
        super(account);
    }

    // 融合装备
    public Result<EquipmentCombineEquipment> combine(Equipment e1, Equipment e2, Equipment e3){
        String s = Arrays.toString(new Integer[]{e1.getEquipmentId(), e2.getEquipmentId(), e3.getEquipmentId()});

        HttpResponse response = HttpRequest.post(config.get("装备融合"))
                .cookie(getCookies())
                .body(s, "application/json")
                .execute();
        return JSONUtil.toBean(response.body(), new TypeReference<Result<EquipmentCombineEquipment>>() {},false);
    }

    // 装备列表
    public Result<List<Equipment>> equipmentsList(){
        HttpResponse response = HttpRequest.get(config.get("装备列表"))
                .cookie(getCookies())
                .execute();
        return JSONUtil.toBean(response.body(), new TypeReference<Result<List<Equipment>>>() {},false);
    }

    // 蓝色装备
    public List<Equipment> getBlueEquipment(){
        Result<List<Equipment>> result =  equipmentsList();
        return result.getData().stream()
                .filter(new EquipmentLevelFilter(EquipmentLevelFilter.BLUE))
                .collect(Collectors.toList());
    }


    // 卖装备
    public Result<String> sold(Equipment equipment){
        HttpResponse response = HttpRequest.post(config.get("卖装备") + equipment.getEquipmentId())
                .cookie(getCookies())
                .execute();
        return JSONUtil.toBean(response.body(), new TypeReference<Result<String>>() {},false);
    }

    // 卖装备
    public void sold(List<Equipment> equipments){
        equipments.forEach(this::sold);
    }


    public Integer getType(Equipment equipment){
        return equipment.getType();
    }


}
